package com.qidi.controller;

import com.qidi.bean.Emp;
import com.qidi.bean.Msg;
import com.qidi.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhouXinBin
 * @create 2020-11-04-9:50
 */
@Controller
public class EmpController {
    @Autowired
    EmpService empService;

    @GetMapping("/emps")
    @ResponseBody
    public Msg firstPage(){
        System.out.println("123");
        List<Emp> emps = empService.queryAll();
        return Msg.success().add("emps",emps);
    }

    @GetMapping("/emp/add")
    @ResponseBody
    public Msg add(Emp emp){
        System.out.println(emp);
        empService.saveEmp(emp);
        return Msg.success();
    }

    @GetMapping("/emp/delete")
    @ResponseBody
    public Msg delete(@RequestParam("id") Integer id){
        empService.deleteEmp(id);
        return Msg.success();
    }
}
